package com.ruoyi.report_lqhhl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.ruoyi.report_lqhhl.domain.bo.ReportLqhhlMxetjf1jlbBsDetail2Bo;
import com.ruoyi.report_lqhhl.domain.vo.ReportLqhhlMxetjf1jlbBsDetail2Vo;
import com.ruoyi.report_lqhhl.domain.ReportLqhhlMxetjf1jlbBsDetail2;
import com.ruoyi.report_lqhhl.mapper.ReportLqhhlMxetjf1jlbBsDetail2Mapper;
import com.ruoyi.report_lqhhl.service.IReportLqhhlMxetjf1jlbBsDetail2Service;

import java.util.List;
import java.util.Map;
import java.util.Collection;

/**
 * 沥青混合料马歇尔试验检测记录(体积法)1详情2Service业务层处理
 *
 * @author llb
 * @date 2024-08-19
 */
@RequiredArgsConstructor
@Service
public class ReportLqhhlMxetjf1jlbBsDetail2ServiceImpl implements IReportLqhhlMxetjf1jlbBsDetail2Service {

    private final ReportLqhhlMxetjf1jlbBsDetail2Mapper baseMapper;

    /**
     * 查询沥青混合料马歇尔试验检测记录(体积法)1详情2
     */
    @Override
    public ReportLqhhlMxetjf1jlbBsDetail2Vo queryById(Long id){
        return baseMapper.selectVoById(id);
    }

    /**
     * 查询沥青混合料马歇尔试验检测记录(体积法)1详情2列表
     */
    @Override
    public TableDataInfo<ReportLqhhlMxetjf1jlbBsDetail2Vo> queryPageList(ReportLqhhlMxetjf1jlbBsDetail2Bo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<ReportLqhhlMxetjf1jlbBsDetail2> lqw = buildQueryWrapper(bo);
        Page<ReportLqhhlMxetjf1jlbBsDetail2Vo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 查询沥青混合料马歇尔试验检测记录(体积法)1详情2列表
     */
    @Override
    public List<ReportLqhhlMxetjf1jlbBsDetail2Vo> queryList(ReportLqhhlMxetjf1jlbBsDetail2Bo bo) {
        LambdaQueryWrapper<ReportLqhhlMxetjf1jlbBsDetail2> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<ReportLqhhlMxetjf1jlbBsDetail2> buildQueryWrapper(ReportLqhhlMxetjf1jlbBsDetail2Bo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<ReportLqhhlMxetjf1jlbBsDetail2> lqw = Wrappers.lambdaQuery();
        lqw.eq(bo.getExcelId() != null, ReportLqhhlMxetjf1jlbBsDetail2::getExcelId, bo.getExcelId());
        lqw.eq(StringUtils.isNotBlank(bo.getXvh()), ReportLqhhlMxetjf1jlbBsDetail2::getXvh, bo.getXvh());
        lqw.eq(bo.getZhij1() != null, ReportLqhhlMxetjf1jlbBsDetail2::getZhij1, bo.getZhij1());
        lqw.eq(bo.getZhij2() != null, ReportLqhhlMxetjf1jlbBsDetail2::getZhij2, bo.getZhij2());
        lqw.eq(bo.getZhij3() != null, ReportLqhhlMxetjf1jlbBsDetail2::getZhij3, bo.getZhij3());
        lqw.eq(bo.getZhij4() != null, ReportLqhhlMxetjf1jlbBsDetail2::getZhij4, bo.getZhij4());
        lqw.eq(bo.getZhijpjz() != null, ReportLqhhlMxetjf1jlbBsDetail2::getZhijpjz, bo.getZhijpjz());
        lqw.eq(bo.getGaod1() != null, ReportLqhhlMxetjf1jlbBsDetail2::getGaod1, bo.getGaod1());
        lqw.eq(bo.getGaod2() != null, ReportLqhhlMxetjf1jlbBsDetail2::getGaod2, bo.getGaod2());
        lqw.eq(bo.getGaod3() != null, ReportLqhhlMxetjf1jlbBsDetail2::getGaod3, bo.getGaod3());
        lqw.eq(bo.getGaod4() != null, ReportLqhhlMxetjf1jlbBsDetail2::getGaod4, bo.getGaod4());
        lqw.eq(bo.getGaodpjz() != null, ReportLqhhlMxetjf1jlbBsDetail2::getGaodpjz, bo.getGaodpjz());
        lqw.eq(bo.getTij() != null, ReportLqhhlMxetjf1jlbBsDetail2::getTij, bo.getTij());
        lqw.eq(bo.getGanzsjkzzl() != null, ReportLqhhlMxetjf1jlbBsDetail2::getGanzsjkzzl, bo.getGanzsjkzzl());
        lqw.eq(bo.getMaotjxdmd() != null, ReportLqhhlMxetjf1jlbBsDetail2::getMaotjxdmd, bo.getMaotjxdmd());
        lqw.eq(bo.getKongxl() != null, ReportLqhhlMxetjf1jlbBsDetail2::getKongxl, bo.getKongxl());
        lqw.eq(bo.getYouxlqtjbfl() != null, ReportLqhhlMxetjf1jlbBsDetail2::getYouxlqtjbfl, bo.getYouxlqtjbfl());
        lqw.eq(bo.getJianxl() != null, ReportLqhhlMxetjf1jlbBsDetail2::getJianxl, bo.getJianxl());
        lqw.eq(bo.getLqbhd() != null, ReportLqhhlMxetjf1jlbBsDetail2::getLqbhd, bo.getLqbhd());
        lqw.eq(bo.getCujlgjjxl() != null, ReportLqhhlMxetjf1jlbBsDetail2::getCujlgjjxl, bo.getCujlgjjxl());
        lqw.eq(bo.getWendd() != null, ReportLqhhlMxetjf1jlbBsDetail2::getWendd, bo.getWendd());
        lqw.eq(bo.getLiuz() != null, ReportLqhhlMxetjf1jlbBsDetail2::getLiuz, bo.getLiuz());
        lqw.eq(bo.getMaxems() != null, ReportLqhhlMxetjf1jlbBsDetail2::getMaxems, bo.getMaxems());
        return lqw;
    }

    /**
     * 新增沥青混合料马歇尔试验检测记录(体积法)1详情2
     */
    @Override
    public Boolean insertByBo(ReportLqhhlMxetjf1jlbBsDetail2Bo bo) {
        ReportLqhhlMxetjf1jlbBsDetail2 add = BeanUtil.toBean(bo, ReportLqhhlMxetjf1jlbBsDetail2.class);
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setId(add.getId());
        }
        return flag;
    }

    /**
     * 修改沥青混合料马歇尔试验检测记录(体积法)1详情2
     */
    @Override
    public Boolean updateByBo(ReportLqhhlMxetjf1jlbBsDetail2Bo bo) {
        ReportLqhhlMxetjf1jlbBsDetail2 update = BeanUtil.toBean(bo, ReportLqhhlMxetjf1jlbBsDetail2.class);
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(ReportLqhhlMxetjf1jlbBsDetail2 entity){
        //TODO 做一些数据校验,如唯一约束
    }

    /**
     * 批量删除沥青混合料马歇尔试验检测记录(体积法)1详情2
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteBatchIds(ids) > 0;
    }
}
